package com.zm.zb100.controller;

import com.zm.zb100.persistence.entity.db.EpsCommodityAttractDesign;
import com.zm.zb100.persistence.entity.db.User;
import com.zm.zb100.persistence.entity.dto.PageResultDTO;
import com.zm.zb100.persistence.entity.dto.PagedDTO;
import com.zm.zb100.service.EpsCommodityAttractDesignService;
import com.zm.zb100.test.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author chuanbai
 * @date 2024/3/29 1:30
 * @deception
 */
@RestController
public class EpsCommodityAttractDesignController {

    @Resource
    private EpsCommodityAttractDesignService epsCommodityAttractDesignService;


    @PostMapping("/insertEpsCommodityAttractDesign")
    public ResponseEntity insertEpsCommodityAttractDesign(@RequestBody EpsCommodityAttractDesign epsCommodityAttractDesign,
                                                          User user){
        System.out.println(epsCommodityAttractDesign.getDesignNo());
        if (!"管理员".equals(user.getRole())){
            return null;
        }
        Boolean aBoolean = epsCommodityAttractDesignService.insertEpsCommodityAttractDesign(epsCommodityAttractDesign);
        if (!aBoolean){
            return new ResponseEntity(Boolean.FALSE, HttpStatus.INTERNAL_SERVER_ERROR);
        }
        return new ResponseEntity(Boolean.TRUE, HttpStatus.OK);
    }

    public ResponseEntity fingByChannel(String channel){
        return new ResponseEntity(epsCommodityAttractDesignService.getByChannel(channel),HttpStatus.OK);
    }

    @GetMapping("/test")
    public String test(){
        return Arrays.asList("111","222").toString();
    }

    @GetMapping("/test/aa")
    public ResponseEntity aa(){
        return new ResponseEntity(Arrays.asList("111","222").toString(), HttpStatus.OK);
    }


    @PostMapping("/inserList")
    public ResponseEntity insertList(@RequestBody List<EpsCommodityAttractDesign> epsCommodityAttractDesignList,
                                     User user){
        System.out.println(epsCommodityAttractDesignList);
//        if (!"管理员".equals(user.getRole())){
//            return null;
//        }
        Boolean aBoolean = epsCommodityAttractDesignService.insertList(epsCommodityAttractDesignList);
        if (!aBoolean){
            return new ResponseEntity(Boolean.FALSE, HttpStatus.INTERNAL_SERVER_ERROR);
        }
        return new ResponseEntity(Boolean.TRUE, HttpStatus.OK);
    }

    @PostMapping("/updateList")
    public Boolean updateList(@RequestBody List<EpsCommodityAttractDesign> epsCommodityAttractDesignList){
        return epsCommodityAttractDesignService.updateList(epsCommodityAttractDesignList);
    }

    @PostMapping("/deleteList")
    public Boolean deleteList(@RequestBody List<EpsCommodityAttractDesign> epsCommodityAttractDesignList){
        return epsCommodityAttractDesignService.deleteList(epsCommodityAttractDesignList);
    }

    @PostMapping("/deleteByOne")
    public Boolean deleteByOne(@RequestBody List<EpsCommodityAttractDesign> epsCommodityAttractDesignList){
        return epsCommodityAttractDesignService.deleteByOne(epsCommodityAttractDesignList);
    }

    @PostMapping("/findPage")
    public ResponseEntity findPage(){
        Page page = epsCommodityAttractDesignService.findPage();
        return new ResponseEntity(page,HttpStatus.OK);
    }

    @PostMapping("/t")
    public ResponseEntity t(){
        PagedDTO page = new PagedDTO(1, 3L, "1");
        Result<PagedDTO> objectResult = new Result<PagedDTO>().setResult(page);
        return new ResponseEntity<>(objectResult,HttpStatus.OK);
    }
}
